class DashboardController < ApplicationController
  layout "mytodo", :except => "show_todo_notes"   
  
  before_filter :authorize
  
  def index
    session[:date] = Date.today if !session[:date] || params[:today]
    if params[:move]
    	case params[:move].to_i
    	when 0
    		session[:date] = params[:seldate].to_date 
    	else
      		session[:date] = session[:date] + params[:move].to_i
    	end  
    end
    
    if params[:user]
      user_id = params[:user]
    else
      user_id = session[:user_id]
    end
  	@user = User.find(user_id)
    @todos = Todo.find_todos_for_me(user_id, :date => session[:date])
    @expires = @user.find_expired_todos
		@users = Role.find_by_name("user").users
		#@users = User.find(:all)
    #logger.info ("User #{session[:user_id]} has #{@todos.count} todos.")
  end
  
  def done
    @todo = Todo.find(params[:id])
    #@todo.check_state = true
    #if @todo.update
    if @todo.done
      flash[:notice] = 'Todo was successfully done.'      
    else
      flash[:notice] = 'Todo was not done.'  
    end  
    redirect_to :action => 'index'
  end
  
    def show_todo_notes
       @todo = Todo.find(params[:id])        
       @notes = @todo.notes(:refresh)
    end
end
